package com.pfa.test.controllers;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.pfa.test.entities.ClientDsi;
import com.pfa.test.entities.DemandeReparation;
import com.pfa.test.entities.Intervenant;
import com.pfa.test.metier.IIntervenantMetier;

@Controller
@RequestMapping("/espaceIntervenant")
public class IntervenantController {

		@Autowired
		private IIntervenantMetier metier;
		
		@RequestMapping(value="/index")
		public String index(Model model,HttpServletRequest request, String login){ 
			try {
				Intervenant intervenant = metier.getIntervenant(login);
				System.out.println(login +"  ------------------ "+ intervenant.getIntitule());
			
				if(intervenant != null){
					HttpSession session = request.getSession();
					session.setAttribute("intitule", login);
					session.setAttribute("intervenant", intervenant);
					model.addAttribute("reparations", metier.listReparation(intervenant.getIdIntervanant()));
					System.out.println("intervenant !");
					return "Intervenant/home";
				}
			} catch (Exception e) {
				System.out.println("exception");
				e.printStackTrace();
				return "redirect:/";
			}	
			
			return "redirect:/";
		}
		
//		@RequestMapping(value="/editRep")
//		public String modifierReparation(Model model){
//			DemandeReparation rep=new DemandeReparation();
//			model.addAttribute(rep);
//			return "Intervenants/editerReparation";
//		}
}
